package com.xgggh.redpack.base.viewbinder;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Parcelable;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;

import com.xgggh.redpack.base.ui.BaseActivity;
import com.xgggh.redpack.domain.app.IntentFlag;
import me.drakeet.multitype.ItemViewBinder;
import me.drakeet.multitype.Items;
import me.drakeet.multitype.MultiTypeAdapter;

public  abstract class BaseItemViewBinder<T extends Parcelable>  extends ItemViewBinder<T,BinderViewHolder>{
    protected MultiTypeAdapter adapter = new MultiTypeAdapter();
    protected Items items = new Items();

    @NonNull
    public abstract int getResId();
    public  BaseActivity baseActivity;
    @NonNull
    @Override
    protected BinderViewHolder onCreateViewHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        ViewDataBinding binding= DataBindingUtil.inflate(inflater, getResId(),parent,false);
        return new BinderViewHolder(binding.getRoot());
    }

    @Override
    protected void onBindViewHolder(@NonNull BinderViewHolder holder, @NonNull T item) {
         baseActivity=((BaseActivity)holder.itemView.getContext());
    }

    protected void startActivity(Context context, Class<? extends Activity> target, T t){
       Intent intent= new Intent(context, target);
        intent.putExtra(IntentFlag.data,t);
       context.startActivity(intent);
    }


}
